package web;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.User;

import service.UserService;
import util.ServletUtil;

public class mainServlet extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		UserService service=new UserService();
		
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		String pic=request.getParameter("pic");
		
		User user=service.login(username, password,pic);
		
		if(user!=null){
			ServletUtil.setSessionAttribute(request,username,password);
			ServletUtil.redirect(response,"home.jspx");
			
		}else{
			
			ServletUtil.redirect(response,"login.jspx?state=10001");
		}
	}

	

}
